package com.fxpc.hddc.disaster.jpa.dao.primary;

import com.fxpc.hddc.disaster.dto.primary.entity.YhDisasterEntity;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.util.List;


/**
 * @author zyb
 * @date 2020-11-30
 */
@Repository
public interface YhDisasterBaseDao extends JpaRepository<YhDisasterEntity, String> {

    @Query(nativeQuery = true, value = "select * from yh_disaster where is_valid = '1' and yh_project_type in ('住宅','大中小学校舍','医疗卫生设施', '社会服务保障设施', '商业中心')")
    List<YhDisasterEntity> findFwALlTime();

    @Query(nativeQuery = true, value = "select * from yh_disaster where SUBSTRING(create_time,1,10)= :nowDay AND is_valid = '1' and yh_project_type in ('住宅','大中小学校舍','医疗卫生设施', '社会服务保障设施', '商业中心')")
    List<YhDisasterEntity> findFwOneDayDataByCreateTime(@Param(value = "nowDay") LocalDate nowDay);

    @Query(nativeQuery = true, value = "select * from yh_disaster where is_valid = '1' and yh_project_type like '%桥梁%'")
    List<YhDisasterEntity> findSzALlTime();

    @Query(nativeQuery = true, value = "select * from yh_disaster where SUBSTRING(create_time,1,10)= :nowDay AND " +
            "is_valid = '1' and yh_project_type like '%桥梁%'")
    List<YhDisasterEntity> findSzOneDayDataByCreateTime(@Param(value = "nowDay") LocalDate nowDay);


    //城市自来水厂地震隐患评估成果图
    @Query(nativeQuery = true, value = "select * from yh_disaster where is_valid = '1' and yh_project_type like '%水%'")
    List<YhDisasterEntity> findCsALlTime();

    @Query(nativeQuery = true, value = "select * from yh_disaster where SUBSTRING(create_time,1,10)= :nowDay AND is_valid = '1' and yh_project_type like '%水%'")
    List<YhDisasterEntity> findCsOneDayDataByCreateTime(@Param(value = "nowDay") LocalDate nowDay);

    Long count(Specification<YhDisasterEntity> specification);

}
